package com.mriassl.stream.schedule;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.mriassl.stream.domain.TransactionDO;
import com.mriassl.stream.mapper.TransactionMapper;

@Component
public class BettingSchedule {

    @Autowired
    private RabbitTemplate rabbitTemplate;
    
    @Autowired
    private TransactionMapper transactionMapper;
    
    @Scheduled(cron="*/15 * * * * ?")
    public void executeTransactionTask() {
        List<TransactionDO> items = transactionMapper.selectAll();
        if(!items.isEmpty()) {
            items.parallelStream().forEach(i -> {
                rabbitTemplate.convertAndSend(i.getExchange(), i.getRoutekey(), i.getSendinfo());
            });
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            System.out.println(format.format(new Date())+"：执行调度程序");
        }
    }
    
}
